package com.fourhats.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name="image")
public class Image extends com.fourhats.model.Entity{

	public Image() {
	}
	
	public Image(String path, boolean isPrincipal) {
		this.path = path;
		this.isPrincipal = isPrincipal;
	}
	
	@Column(name="path")
	private String path;
	
	@Column(name="isPrincipal")
	private boolean isPrincipal;

	@ManyToOne
    @JoinColumn(name="productId", 
            insertable=false, updatable=false, 
            nullable=false)
	private Product product;

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public boolean getIsPrincipal() {
		return isPrincipal;
	}

	public void setIsPrincipal(boolean isPrincipal) {
		this.isPrincipal = isPrincipal;
	}
	
	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}
	
	public String toString() {
		return this.path;
	}
	
	public boolean equals(Object obj){
		if(obj == null || !(obj instanceof Image)){
			return false;
		}
		
		if(obj == this){
			return true;
		}
		
		Image img = (Image)obj;
		return img.getId().equals(this.getId());
	}
}
